<span id="${uuid}"></span>

<div class="box_tc_s">
    <form data-id="form-horizontal-resource-update" method="post"
          action="${pageContext.request.contextPath}/app/api/resource/updateResourceForJson">
        <input type="hidden" name="id" value="${resource.id}">
        <input type="hidden" name="permission" value="${resource.permission}"/>
        <table border="1" class="hydra-table" cellpadding="0" cellspacing="0">
            <tr class="hydra-tr-bg">
                <td class="hydra-left">资源名称：</td>
                <td class="hydra-right"><input type="text" data-id="resourceName"
                                               name="resourceName" class="easyui-validatebox hydra-input-width"
                                               data-options="required:true,validType:['normalChar','length[0,20]']"
                                               placeholder="资源名称.." value="${resource.resourceName}"/></td>
            </tr>
            <tr>
                <td class="hydra-left">资源类型：</td>
                <td class="hydra-right">
                    ${resource.resourceType eq 'menu' ? '菜单' : '其他'}
                    <input data-id="resourceType" type="hidden" value="${resource.resourceType}" name="resourceType"/>
                </td>
            </tr>
            <tr>
                <td class="hydra-left">资源图标：</td>
                <td class="hydra-right">
                    <input type="text" data-id="uploadCover" name="icon" value="${resource.icon}"/>
                </td>
            </tr>
            <c:if test="${not empty resource.resourceUrl}">
                <tr class="hydra-tr-bg">
                    <td class="hydra-left">资源路径:</td>
                    <td class="hydra-right">
                            ${resource.resourceUrl}
                            <%--<input type="text" data-id="resourceUrl"--%>
                            <%--autocomplete="off" name="resourceUrl" class="easyui-validatebox hydra-input-width"--%>
                            <%--data-options="validType:['length[0,200]']"--%>
                            <%--placeholder="资源路径.." value="${resource.resourceUrl}"/>--%>
                        <input type="hidden" value="${resource.resourceUrl}" name="resourceUrl"/>
                    </td>
                </tr>
            </c:if>
            <tr>
                <td class="hydra-left">权限码：</td>
                <td class="hydra-right">${resource.permission}</td>
            </tr>
            <tr>
                <td class="hydra-left">父级资源：</td>
                <td class="hydra-right">
                    <select name="parentId" style="width: 360px" data-id="parentId" class="hydra-input-width"></select>
                    <a href="#" data-id="reset" iconCls="fa fa-times-circle fa-lg" plain="true">重置</a>
            </tr>
            <tr>
                <td class="hydra-left">资源序号：</td>
                <td class="hydra-right">
                    <input type="text" autocomplete="off" name="orderNo"
                           class="easyui-numberbox hydra-input-width"
                           data-options="required:true,min:0" value="${resource.orderNo}"/>
                </td>
            </tr>
            <tr class="hydra-tr-bg">
                <td class="hydra-left">资源状态：</td>
                <td class="hydra-right">
                    <input type="checkbox" name="available"
                           data-id="available" ${resource.available eq 1 ? "checked": ""} value="1"/>
                </td>
            </tr>
        </table>
    </form>
</div>
<script type="text/javascript">
    seajs.use(["apps/file", "apps/easyui"], function () {
        var uuid = "${uuid}";
        var page = new $.PageDomFactory(uuid);
        var resourceType = page.getJqDom("resourceType").val();
        page.getJqDom("available").toggleButton({
            dataRef: {
                "0": "禁用",
                "1": "启用"
            }
        });
        //根据地址不同加载不同的数据，如果是menu则加载所有非当前目录的父级菜单，如果是按钮则加载所有菜单
        //组装参数
        var params = ["filterIds[0]=" + page.getJqDom("id").val(),
            "resourceType=menu"];
        page.getJqDom("parentId").resourceSelect({
            url: "${ctx}/app/api/resource/queryResourceByPageForJson?" + params.join("&"),
            value: "${resource.sysResource.id}",
            store: [{
                id: "${resource.sysResource.id}",
                resourceName: "${resource.sysResource.resourceName}"
            }],
            form: {
                items: ['<span class="mr10">按资源名称：</span><input name="resourceName" class="hydra-input-width" placeholder="资源名称..."/>']
            }
        });
        page.getJqDom("reset").linkbutton({
            onClick: function () {
                page.getJqDom("parentId").resourceSelect("clear");
            }
        });
        page.getJqDom('uploadCover').baseImageUpload({
            imageSize: [16, 16],
            'uploader': '${ctx}/app/api/file/uploadTempFile'
        });
        $[uuid] = {
            pageFactory: page
        }
    });

    function resource_edit_save(win) {
        if (!$["${uuid}"].pageFactory.getJqDom('form-horizontal-resource-update').form('validate')) {
            return false;
        }
        win.wait("start", "保存中,请稍候.");
        var form = $["${uuid}"].pageFactory.getJqDom("form-horizontal-resource-update");
        var postData = form.serializeJson();
        $.post(form.attr(
            "action")
            + "?random=" + Math.random(), $.utils.buildJson(postData),
            function (json) {
                win.wait("end");
                if ($.isPlainObject(json) && json.error) {
                    $.messager.alert('信息',
                        json.msg, 'info');
                } else {
                    $.messager.alert('信息',
                        '保存成功', 'info');
                    win.callback(true);
                    win.close();
                }
            }, "json");
    }
</script>
